package me.szlx.validation;

import me.szlx.validation.namespace.NameSpace;

public class Validators {
    private Validators(){}
    /**
     * 获取指定约束的校验器。
     *
     * @param constraintCodeOrBrief 约束代码或描述。
     * @return 为指定约束创建新的校验器。
     */
    public static Validator of(String constraintCodeOrBrief) {
        return ValidatorFactory.of(constraintCodeOrBrief);
    }

    /**
     * 获取指定约束的校验器。
     *
     * @param constraint 约束代码或描述。
     * @return 为指定约束创建新的校验器。
     */
    public static Validator of(Constraint constraint) {
        return ValidatorFactory.of(constraint);
    }

    public static void invalid(String constraintCodeOrBrief) {
        Assert.constraintNotNull(constraintCodeOrBrief);
        of(constraintCodeOrBrief).invalid();
    }

    public static void invalid(String constraintCodeOrBrief, NameSpace nameSpace) {
        Assert.constraintNotNull(constraintCodeOrBrief);
        of(constraintCodeOrBrief).invalid(nameSpace);
    }

    public static void invalid(String constraintCodeOrBrief, Throwable throwable) {
        Assert.constraintNotNull(constraintCodeOrBrief);
        of(constraintCodeOrBrief).invalid(throwable);
    }

    public static void invalid(String constraintCodeOrBrief, NameSpace nameSpace, Throwable throwable) {
        Assert.constraintNotNull(constraintCodeOrBrief);
        of(constraintCodeOrBrief).invalid(nameSpace, throwable);
    }

    public static void invalid(Constraint constraint) {
        Assert.constraintNotNull(constraint);
        of(constraint).invalid();
    }

    public static void invalid(Constraint constraint, NameSpace nameSpace) {
        Assert.constraintNotNull(constraint);
        of(constraint).invalid(nameSpace);
    }

    public static void invalid(Constraint constraint, Throwable throwable) {
        Assert.constraintNotNull(constraint);
        of(constraint).invalid(throwable);
    }

    public static void invalid(Constraint constraint, NameSpace nameSpace, Throwable throwable) {
        Assert.constraintNotNull(constraint);
        of(constraint).invalid(nameSpace, throwable);
    }

    public static void invalidIf(boolean predicate, String constraintCodeOrBrief) {
        if (predicate) {
            invalid(constraintCodeOrBrief);
        }
    }

    public static void invalidIf(boolean predicate, String constraintCodeOrBrief, NameSpace nameSpace) {
        if (predicate) {
            invalid(constraintCodeOrBrief, nameSpace);
        }
    }

    public static void invalidIf(boolean predicate, Constraint constraint) {
        Assert.constraintNotNull(constraint);
        if (predicate) {
            invalid(constraint);
        }
    }

    public static void invalidIf(boolean predicate, Constraint constraint, NameSpace nameSpace) {
        Assert.constraintNotNull(constraint);
        if (predicate) {
            invalid(constraint, nameSpace);
        }
    }

    public static void invalidIf(Conditional conditional, String constraintCodeOrBrief) {
        Assert.notNull(conditional, "校验约束不能为null");
        invalidIf(conditional.apply(), constraintCodeOrBrief);
    }

    public static void invalidIf(Conditional conditional, String constraintCodeOrBrief, NameSpace nameSpace) {
        Assert.notNull(conditional, "校验约束不能为null");
        invalidIf(conditional.apply(), constraintCodeOrBrief, nameSpace);
    }

    public static void invalidIf(Conditional conditional, Constraint constraint) {
        Assert.constraintNotNull(constraint);
        Assert.conditionalNotNull(conditional);
        invalidIf(conditional.apply(), constraint);
    }

    public static void invalidIf(Conditional conditional, Constraint constraint, NameSpace nameSpace) {
        Assert.constraintNotNull(constraint);
        Assert.conditionalNotNull(conditional);
        invalidIf(conditional.apply(), constraint, nameSpace);
    }
}
